package com.justreading.netty.protobuftcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 11 月 09 日 下午7:46
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println("MyMessageEncoder 被调用");
        System.out.println("发送消息 ====>"  + msg);
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }
}
